package com.argrace.smart.entity;

import java.io.Serializable;

/**
 * Created by argrace_dev_1 on 2018/2/2.
 */

public class Key_ValueEntity implements Serializable {

    private String value;
    private String when;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getWhen() {
        return when;
    }

    public void setWhen(String when) {
        this.when = when;
    }

    @Override
    public String toString() {
        return "{\"value\":\"" + value + "\",\"when\":\"" + when + "\"}";
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        if (o instanceof Key_ValueEntity) {
            Key_ValueEntity entity = (Key_ValueEntity) o;
            return entity.getValue().equals(value);
        }
        return false;
    }

    /**
     * 比较大小方法,比较对象为空||大于比较对象返回1，
     * 相等返回0
     * 小于比较对象返回-1
     */
    public int compareValue(Object o) {
        if (o == null) {
            return 1;
        }
        if (o instanceof Key_ValueEntity) {
            Key_ValueEntity entity = (Key_ValueEntity) o;
            if (Float.parseFloat(value) > Float.parseFloat(entity.getValue())) {
                return 1;
            }
            if (Float.parseFloat(value) == Float.parseFloat(entity.getValue())) {
                return 0;
            }
            if (Float.parseFloat(value) < Float.parseFloat(entity.getValue())) {
                return -1;
            }
        }
        return 1;
    }

    //是否大于等于
    public boolean isEqualOrGreater(Object o) {
        if (o == null) {
            return true;
        }
        if (o instanceof Key_ValueEntity) {
            Key_ValueEntity entity = (Key_ValueEntity) o;
            if (Float.parseFloat(value) >= Float.parseFloat(entity.getValue())) {
                return true;
            }
        }
        return false;
    }

    //是否小于等于
    public boolean isEqualOrless(Object o) {
        if (o == null) {
            return true;
        }
        if (o instanceof Key_ValueEntity) {
            Key_ValueEntity entity = (Key_ValueEntity) o;
            if (Float.parseFloat(value) <= Float.parseFloat(entity.getValue())) {
                return true;
            }
        }
        return false;
    }

    public boolean notNull() {
        return this != null && this.value != null;
    }
}
